﻿using System;
using E_Commerce.Domain.Entities;
using E_Commerce.Domain.Interfaces;//引用
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using AutoMapper;//引用AutoMapper
using E_Commerce.Application.Dto;


namespace E_Commerce.Application
{
    /// <summary>
    /// 商品规格
    /// </summary>
   public class SepcService:ISepcService
    {
        private ISpecificationRepository _specRepository;
        public SepcService(ISpecificationRepository specRepository)
        {
            this._specRepository = specRepository;
        }
        /// <summary>
        /// 添加规格
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public async Task<int> AddSpecAsyn(Specification s)
        {
            try
            {
                return await _specRepository.AddSpecAsyn(s);
            }
            catch (Exception ex)
            {

                throw new Exception(ex.Message);
            }
            
        }
        /// <summary>
        /// 删除规格
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> DeleSpecAsync(int id)
        {
            return await _specRepository.DeleSpecAsync(id);
        }
        /// <summary>
        /// 反填规格
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Specification FillSpecAsync(int id)
        {
            return _specRepository.FillSpecAsync(id);
        }
        /// <summary>
        /// 显示规格
        /// </summary>
        /// <returns></returns>
        public List<Specification> GetSpecifications(int id)
        {
            return _specRepository.GetSpecifications(id);
        }
        /// <summary>
        /// 修改规格
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public async Task<int> UptSpecAsync(Specification s)
        {
            try
            {
                return await _specRepository.UptSpecAsync(s);
            }
            catch (Exception ex)
            {

                throw new Exception(ex.Message);
            }
            
        }
    }
}
